<include file="Public:header" />

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

<script type="text/javascript">

    $(function () {

        var d = "{$jsApiParameters | default = ''}";

        if (!d) {

            d = {};

            alert("jsApiParameters初始化错误");
        }

        $(".form-group").click(function () {

            var paytype = '';

            $('input[name="payfor"][checked]').each(function () {
                paytype = $(this).val();
            });

            if (paytype == 'weixin') {

                callpay();
            } else if (paytype == 'score') {

                score();
            }

            return false;
        });

//       支付方式选择
        $(".check-box .pay-way").click(
                function () {
                    $(this).children('.checked').css("background-position", "left bottom");
                    $(this).parent().siblings().children(".pay-way").children('.checked').css("background-position", "left top");
                    $(this).children("input").attr("checked", "checked");
                    $(this).parent().siblings().children(".pay-way").children('input').removeAttr("checked", "checked");
                }
        );

        function callpay()
        {
            alert('微信支付');
            return;
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            } else {
                jsApiCall();
            }
        }

        //调用微信JS api 支付
        function jsApiCall()
        {
            WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', d,
                    function (res) {
                        WeixinJSBridge.log(res.err_msg);

                        switch (res.err_msg) {
                            case 'get_brand_wcpay_request:cancel':
                                alert("您取消了支付");
                                break;
                            case 'get_brand_wcpay_request:fail':
                                alert("支付失败");
                                break;
                            case 'get_brand_wcpay_request:ok':
                                alert("支付成功");
                                window.href.location = "{:U('Member/order')}";
                                break;
                        }
                    }
            );
        }

        function score() {

            alert('积分支付');
//            return;

            var paymoney = "{$order_info['total']}";

            var balance = "{$balance}";
            
//            var compare = accSub(balance,paymoney);  
//            
//            if(compare < 0){
//                
//                jAlert('余额不足',''); return;
//            }
            
//            var url = "{:U('Pay/pay_type')}" + '&order_id='+"{$order_info.id}";
//            
//            alert(url);return;
            
            window.location.href = "{:U('Pay/pay_type')}" + '&order_id='+"{$order_info.id}";

        }

        function accSub(arg1, arg2) {
            return accAdd(arg1, -arg2);
        }

        function accAdd(arg1, arg2) {
            var r1, r2, m;
            try {
                r1 = arg1.toString().split(".")[1].length;
            } catch (e) {
                r1 = 0;
            }
            try {
                r2 = arg2.toString().split(".")[1].length;
            } catch (e) {
                r2 = 0;
            }
            m = Math.pow(10, Math.max(r1, r2));
            return (arg1 * m + arg2 * m) / m;
        }
    });

</script>

<style>
    .form-group{position:fixed; max-width: 620px; width:100%; bottom: 55px; text-align: center; background: #5cb85c none repeat scroll 0 0; padding: 10px 0 }

    .form-group a{color:#fff;}

    #main{background: #EFEFEF}
</style>

<div id="main">

    <include file="Public:procat" />

    <div class="goodslist" style="padding:0 5px;">

        <div class="jiezhi" style="text-align: center; border: 1px solid #eaeaea;background: #fff">
            <p style="padding:30px 0px; font-size:18px;"><span><img src="__PUBLIC__/front/images/pay_index_img/clock.png"></span>&nbsp;&nbsp;支付截止时间：{$order_info.create_time|date = 'Y-m-d H:i',###}</p>
        </div>

        <div style="border: 1px solid #eaeaea; margin-top: 20px; padding: 20px 1px 20px 20px; font-size: 16px;background: #fff">
            <p>订单编号：{$order_info.order_no}</p>
            <P>订单金额：{$order_info.total}元</P>
        </div>

    </div>

    <div class="check-box" style="margin: 20px 0; padding: 0 5px;background: #fff">
        <ul style="border: 1px solid #eaeaea;">
            <li style="border-bottom: 1px solid #eaeaea; padding: 10px 20px;">

                <p style="margin: 0;font-size: 18px;">选择支付方式</p>

            </li>

            <li style="overflow: hidden; border-bottom: 1px solid #eaeaea; padding: 8px 20px;">

                <div style="float: left;">

                    <img style="width: 35px;" src="__PUBLIC__/front/images/pay_index_img/wechat.png">

                </div>

                <div style="float: left;padding-left: 15px; ">

                    <h1 style="padding: 0;color: #000000; margin: 0;font-weight: normal;font-size: 14px;">微信支付</h1>

                    <p style="color: #666666;  margin: 0;font-size: 12px;">使用微信支付，方便快捷</p>

                </div>

                <div style="float: right;width:20px; height:20px" class="pay-way" >

                    <input type="radio" name="payfor" value="weixin"  checked style="display: none;"/>

                    <label class="checked" style="background: url(__PUBLIC__/front/images/pay_index_img/pay-bg.gif) no-repeat left bottom; width: 20px;height: 20px; margin-top: 15px; display: block"></label>

                </div>

            </li>	

            <li style="overflow: hidden; border-bottom: 1px solid #eaeaea; padding: 10px 20px;">

                <div style="float: left;">

                    <img style="width: 35px;" src="__PUBLIC__/front/images/pay_index_img/payfor.png">

                </div>

                <div style="float: left;padding-left: 15px; ">

                    <h1 style="padding: 0;color: #000000; margin: 0;font-weight: normal;font-size: 14px;">积分支付[<span style="color:#fa0000">{$balance}</span>]</h1>

                    <p style="color: #666666;  margin: 0;font-size: 12px;">用户使用</p>

                </div>

                <div style="float: right;width:20px; height:20px" class="pay-way">

                    <input  type="radio" name="payfor" value="score"   style="display: none;"/>

                    <label class="checked" style="background: url(__PUBLIC__/front/images/pay_index_img/pay-bg.gif) no-repeat left top; width: 20px;height: 20px; margin-top: 15px;display: block"></label>

                </div>

            </li>

        </ul>

    </div>

    <!--    <div class="form-group">
          <a class="pay_submit" onclick="callpay()">微信支付</a>
      </div>-->

    <div class="form-group">
        <a class="pay_submit">支 付</a>
    </div>

    <script>


    </script>

</div>

<include file="Public:footer" />